/**
 * Looker  新闻整合系统
 * Author  :solosky
 * File    :MonitorManager.java
 * Date    :Jun 18, 2009
 * Lisence : Apache License 2.0 
 */
package net.looker.manager;

import java.util.ArrayList;

import net.looker.monitor.schdule.Monitor;
import net.looker.monitor.schdule.MonitorManager;
import net.looker.monitor.schdule.WorkPoint;

/**
 * 监视器管理代理类
 * @author solosky
 *
 */
public class MonitorManagerAgent implements MonitorManagerAgentMBean
{
	/**
	 * 管理对象
	 */
	private MonitorManager monitorManager;
	/**
	 * 构造函数
	 * @param monitorManger
	 */
	public MonitorManagerAgent(MonitorManager monitorManager)
	{
		this.monitorManager = monitorManager;
		
	}
	/* (non-Javadoc)
	 * @see net.looker.manager.MonitorManagerMBean#getMonitorCount()
	 */
	@Override
	public int retireMonitorCount() {
		return this.monitorManager.getMonitorList().size();
	}

	/* (non-Javadoc)
	 * @see net.looker.manager.MonitorManagerMBean#getMonitorStatus()
	 */
	@Override
	public ArrayList<MonitorStatus> retireMonitorStatus()
	{
		ArrayList<MonitorStatus> statusList = new ArrayList<MonitorStatus> ();
		WorkPoint [] workPointArray = this.monitorManager.getScheduleQueueSnap();
		Monitor  curMonitor  = null;
		MonitorStatus curStatus = null;
		for (int i=0; i<workPointArray.length; i++){
			curStatus = new MonitorStatus();
			curStatus.setNextCheckTime(workPointArray[i].getTime());	//下次更新时间
			
			curMonitor = (Monitor) workPointArray[i].getWork();
			
			curStatus.setHash(curMonitor.getHash());
			curStatus.setName(curMonitor.getName());
			curStatus.setAction(curMonitor.getAction());
			curStatus.setStatus(curMonitor.getStatus());
			curStatus.setInterval(curMonitor.getInterval());
			
			statusList.add(curStatus);
		}
		
		return statusList;
	}

}
